import axios from "axios";
import { ElMessage } from "element-plus";
const instance = axios.create({
    baseURL: "/api",
    timeoute: 2000,
});
instance.interceptors.request.use(
    (config) => {
        return config;
    },
    (error) => {
        return Promise.reject(error);
    }
);

instance.interceptors.response.use((response) => {
    return response;
});
const request = async ({
    url,
    method = "GET",
    data = {},
    params = {},
    headers = {},
}) => {
    const config = {
        method,
        url,
        headers,
        ...(method === "get" ? { params } : { data }),
    };
    const res = await instance(config);
    // if (!res.data.success || res.data.code !== 200) {
    //     ElMessage.warning(res.data.message);
    //     return null;
    // }
    return res.data;
};
export default instance;
export { request };
